Ext.onReady(function(){
	Ext.QuickTips.init();

	// Create a variable to hold our EXT Form Panel.

	// Assign various config options as seen.
	var login = new Ext.FormPanel({
		labelWidth:80,
		url:'utilisateurs/login.action',
		frame:true,
		title:'Authentification MAGIC ERP',
		defaultType:'textfield',
		width:300,
		height:150,
		monitorValid:true,
		items:[{
			fieldLabel:'Login',
			name:'login',
			allowBlank:false
		},{
			fieldLabel:'Mot de passe',
			name:'pw',
			inputType:'password',
			allowBlank:false
		}],
		buttons:[{
			text:'Login',
			formBind: true,
			handler:function(){
				v();
			}
		}],
		keys: [{
			key: [Ext.EventObject.ENTER], handler: function() {
				v();
			}
		}]
	});
	function v()
	{
		login.getForm().submit({
		method:'POST', 
		success:function(){
				window.location = 'desktop.html';
			},
		failure:function(form, action){
				if(action.failureType == 'server'){
					Ext.Msg.alert('Authentification!','Login ou mot de passe incorrect!');
				}else{
					Ext.Msg.alert('Warning!', 'Authentication server is unreachable : ' + action.response.responseText);
				}
				login.getForm().reset();
			}
		});
	}
	login.render('login');
});
